package com.hxzy.shop.controller.order;

import com.github.pagehelper.PageInfo;
import com.hxzy.shop.dto.order.req.OrderCountsReq;
import com.hxzy.shop.dto.order.req.OrderDetailReq;
import com.hxzy.shop.dto.order.req.OrderManageReq;
import com.hxzy.shop.dto.order.resp.OrderCountsResp;
import com.hxzy.shop.dto.order.resp.OrderDetailResp;
import com.hxzy.shop.dto.order.resp.OrderManageListResp;
import com.hxzy.shop.dto.order.resp.StoreResp;
import com.hxzy.shop.feign.order.OrderFeign;
import com.hxzy.shop.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.text.Collator;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

@RestController
@Api(tags = "订单管理")
@RequestMapping("/order")
public class OrderManageController {
    @Resource
    private OrderFeign orderFeign;

    /**
     * 订单列表
     * @param orderManageReq 订单请求体
     * @return 订单分页
     */
    @PostMapping("/getOrderManageList")
    @ApiOperation("订单管理分页")
    public Result<PageInfo<OrderManageListResp>> getOrderManageList(@RequestBody @Validated OrderManageReq orderManageReq) {
        return orderFeign.getOrderManageList(orderManageReq);
    }

   /**
     * 获得所有门店
     *
     * @return 门店集合
     */
   @ApiOperation("订单所有门店")
   @PostMapping("/getStoreList")
   public Result<List<StoreResp>> getStoreList(){
       Collator collator=Collator.getInstance(Locale.CHINESE);
       List<StoreResp> list=orderFeign.getStoreList().getData();
      Collections.sort(list, (o1, o2) ->  collator.getCollationKey(o1.getName()).compareTo(collator.getCollationKey(o2.getName())));
      return Result.success(list);
   }


    /**
     * 获得订单列表总数
     *
     * @return 订单列表总数
     */
    @ApiOperation("获得订单列表总数")
    @PostMapping("/orderCountS")
    public Result<OrderCountsResp> orderCountS() {
        return orderFeign.orderCountS(new OrderCountsReq());
    }

    /**
     * 订单详细
     *
     * @param orderDetailReq 订单详情请求体
     * @return 订单详情
     */
    @ApiOperation("订单详细")
    @PostMapping("/getOrderDetail")
    public Result<OrderDetailResp> getOrderDetail(@RequestBody @Validated OrderDetailReq orderDetailReq) {
        // 设置1 表示后台访问和分店访问 0 表示小程序
        orderDetailReq.setType(1);
        return orderFeign.getOrderDetail(orderDetailReq);
    }
}
